<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\service\NodeService;
use app\common\facade\Arr;
use library\Controller;
use library\tools\Data;
use think\Console;
use think\Db;
use think\exception\HttpResponseException;
use app\common\facade\TransItem;
use app\common\services\JobService;
use app\common\services\PublishJobService;
use app\common\tools\ExportExcel;


/**
 * 用户行为访问统计
 * Class Index
 * @package app\admin\controller
 */
class VisitBehaviorStat extends Controller
{
    public $table = 'BehaviorStat';

    /**
     * 用户行为访问日统计
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {

        $this->title="用户行为访问统计";

        $start_time= $this->request->param('start_time');
        $end_time=$this->request->param('end_time');

        if(!empty($start_time)&&!empty($end_time)){

            $start=strtotime($start_time." 00:00:00");
            $end=strtotime($end_time. " 23:59:59");
            if($start>$end){
                $this->error('开始时间应小于结束时间');
            }
            $data[]=['created_at','between time',[$start, $end]];
        }
        $data[]=['type','EQ',1];

        $query = $this->_query($this->table)
                ->where($data)
                ->like('id')
                ->equal('id,created_at');
        $query->order('id desc')->page(); 
       
    }

    /**
     * 数据列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _index_page_filter(&$data)
    {   

        foreach ($data as &$vo) {

            $vo['add_time'] = date("Y年m月d日",$vo['created_at']);

        }
    }

    /**
     * 用户行为访问月统计
     * @auth true
     */
    public function month(){

        $this->title="用户行为访问统计";

        $start_time= $this->request->param('start_time');
        $end_time=$this->request->param('end_time');

        if(!empty($start_time)&&!empty($end_time)){

            $start=strtotime($start_time." 00:00:00");
            $end=strtotime($end_time. " 23:59:59");
            if($start>$end){
                $this->error('开始时间应小于结束时间');
            }
            $data[]=['created_at','between time',[$start, $end]];
        }
        $data[]=['type','EQ',2];

        $query = $this->_query($this->table)
                ->where($data)
                ->like('id')
                ->equal('id,created_at');
        $query->order('id desc')->page(); 
    }

    /**
     * 数据列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _month_page_filter(&$data)
    {   

        foreach ($data as &$vo) {

            $vo['add_time'] = date("Y年m月",$vo['start_time']);

        }
    }



     /**
     * 用户行为访问总量统计
     * @auth true
     */
    public function total(){

        $this->title="用户行为访问统计";

       
        $data[]=['type','EQ',3];

        $query = $this->_query($this->table)
                ->where($data)
                ->like('id')
                ->equal('id,created_at');
        $query->order('id desc')->page(); 
    }

    /**
     * 数据列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _total_page_filter(&$data)
    {   

        foreach ($data as &$vo) {

            $vo['add_time'] = date("Y年m月d日",$vo['updated_at']);

        }
    }

   
    




  

}
